package com.fishery.processing.controller;


import com.fishery.entity.Result;
import com.fishery.processing.entity.MaterialInventory;
import com.fishery.processing.service.MaterialInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author run
 * @since 2021-03-12
 */
@RestController
@RequestMapping("/processing/material")
@CrossOrigin
@Api(tags = "原料库存相关接口")
public class MaterialInventoryController {

    @Autowired
    private MaterialInventoryService materialService;

    @GetMapping("/{id}/{page}/{size}")
    @ApiOperation("根据加工厂id分页获取库存列表")
    public Result getMaterialOfFactory(@PathVariable(value = "id") String factoryId
                                        , @PathVariable(value = "page") Integer page
                                        , @PathVariable(value = "size") Integer size){
        return Result.success().data(materialService.getMaterialOfFactory(factoryId, page, size));
    }

    @GetMapping("/{id}")
    @ApiOperation("根据加工厂id获取全部库存列表")
    public Result getMaterialOfFactory(@PathVariable(value = "id") String factoryId){
        return Result.success().data(materialService.getMaterialOfFactory(factoryId));
    }

    @PostMapping("/")
    @ApiOperation("添加原料（订单模块调用）")
    public Result createMaterial(@RequestBody @ApiParam(value = "material")MaterialInventory material){
        return materialService.createMaterial(material)
                ? Result.success("添加成功") : Result.success("添加失败");
    }
}

